<!doctype html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>支付订单</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/base.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/detail.css" />
</head>
<body>
<div class="detail" style="padding-bottom:60px;">
    <div class="state">
        <div class="inner">
            <h2>待付款</h2>
            <span><img src="__PUBLIC__/Wx/img/icon04.png"/></span>
            <p>本商品为自提商品，社区店二次分拣，开心享受家乡美味！</p>
        </div>
    </div>
    <div class="money02">
        <h1>乡土味士</h1>
        <h2><neq name="order['total_fee']" value="0">{$order.total_fee}元</neq><if condition="($order['total_fee'] gt 0) AND ($order['level_integral'] gt 0)">+</if><neq name="order['level_integral']" value="0">{$order.level_integral}积分</neq></h2>
        <div class="time03">
            <div class="time-item">支付时间剩余：<if condition="floor($order['endtime']/60/60/24) neq 0"><span id="day_show">0</span>天</if><strong id="hour_show"><s id="h"></s>0</strong>时<strong id="minute_show"><s></s>00</strong>分<strong id="second_show"><s></s>00</strong>秒</div>
        </div>
    </div>
    <div class="payway">
        <ul>
            <li><span style="background:url(__PUBLIC__/Wx/img/jf02.png) no-repeat left center; background-size:23px 20px;">现有积分</span><em>（剩余<b>{$member.credit1}</b>积分）</em></li>
            <if condition="$order['total_fee'] neq 0">
                <if condition="$member['credit2'] lt $order['total_fee']">
                    <li class="no"><span>卡额支付</span><em>（卡额不足，剩余<b>{$member['credit2']}</b>元）</em><input type="radio" name="on" disabled="true"/></li>
                    <else />
                    <li id="code02"><span>卡额支付</span><em>（剩余<b>{$member['credit2']}</b>元）</em><input type="radio" name="on"/></li>
                </if>
                <li class="wxpay"><span style="background:url(__PUBLIC__/Wx/img/wechat02.png) no-repeat left center; background-size:23px 20px;">微信支付</span><input type="radio" checked  class="selected" name="on"/></li>
            </if>
        </ul>
    </div>
    <div class="ordermess">
        <p>创建时间：<?=date("Y-m-d H:i:s",$order['addtime'])?></p>
        <p>订单编号：{$order.order_sn}</p>
    </div>
    <div class="button"><input type="button" value="确认支付"/></div>
    <div class="hint04">
        <div class="shadow">
            <div class="close"></div>
            <form action="" enctype="multipart/form-data" method="post" id="cart_forehead">
                <div class="succeed">
                    <h2>请输入卡额支付密码</h2>
                    <h3>乡土味士</h3>
                    <h4><neq name="order['total_fee']" value="0">{$order.total_fee}元</neq><if condition="($order['total_fee'] gt 0) AND ($order['level_integral'] gt 0)">+</if><neq name="order['level_integral']" value="0">{$order.level_integral}积分</neq></h4>
                    <h5><input type="password" name="password" placeholder="点击输入卡额支付密码"/></h5>
                    <p><input type="button" value="取消" class="left"/><input type="button" value="确定" class="right"/></p>
                </div>
            </form>
        </div>
    </div>
</div>
<script  src="__PUBLIC__/Wx/js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script type="text/javascript">
    $('.payway ul li input').click(function(){
        $(this).addClass("selected").parents('li').siblings('li').children('input').removeClass()
    });
    $(".button").click(function(){
        if($('#code02 input').hasClass("selected")){
            $('.hint04').css('display','block')
        }else if($(".wxpay input").hasClass('selected')){
            //微信支付
            window.location.href="http://www.xiangtws.com/Api/Salepay/exchange_pay?id="+{$order['id']}
            // window.location.href = 'http://www.xiangtws.com/Api/Weixinpay/pay?order_id='+order_id;
        }else{
            // $('.hint04').css('display','none')
            var id = {$order['id']};
            $.post("__MODULE__/Exchange/credit",{id:id},function (d) {
                if(d.state>0){
                    // 支付失败
                    layer.msg(d.val, {icon:1,time:3000});
                }else{
                    //支付成功
                    // console.log(d);
                    window.location.href="__MODULE__/User/index";
                }//end if
            })//end post

        }//end if

    });//end fun
    $('.hint04 .close').click(function(){
        $('.hint04').css('display','none')
    });
    $('.hint04 .left').click(function(){
        $('.hint04').css('display','none')
    });

    //卡额支付
    $(".right").click(function () {
        var formData = new FormData($('#cart_forehead')[0]);
        formData.append("id","{$order['id']}");//增加表id
        formData.append("table","exchange_order");
        formData.append("type","积分兑换");

        $.ajax({
            url: "http://www.xiangtws.com/index.php/Api/Salepay/cardPay",
            method: 'POST',
            data: formData,
            contentType: false, // 注意这里应设为false
            processData: false,
            cache: false,
            success: function(d) {
                // console.log(d);
                if(d.state>0){
                    // 支付失败
                    $('.hint04').css('display','none');
                    // window.location.reload();
                    alert(d.val);
                }else{
                    //支付成功
                    // console.log(d);
                    window.location.href=d.url;
                }//end if
            }
        });//end ajax

    });//end fun
</script>
<script type="text/javascript">
    var intDiff = parseInt({$order['endtime']});//倒计时总秒数量

    function timer(intDiff){
        window.setInterval(function(){
            var day=0,
                hour=00,
                minute=0,
                second=0;//时间默认值
            if(intDiff > 0){
                day = Math.floor(intDiff / (60 * 60 * 24));
                hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            $('#day_show').html(day+"");
            $('#hour_show').html('<s id="h"></s>'+hour+'');
            $('#minute_show').html('<s></s>'+minute+'');
            $('#second_show').html('<s></s>'+second+'');
            intDiff--;
        }, 1000);
    }
    $(function(){
        timer(intDiff);
    });
</script>
</body>
</html>